﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace YXShop.Web.admin.systeminfo
{
    public partial class mouldtype_edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                YXShop.Common.PromptInfo.Popedom("010005002", "对不起，您没有权限进行编辑");
                YXShop.Common.PromptInfo.Popedom("010005004", "对不起，您没有权限进行编辑");
                InitWebControl();
                GetModel();
                int isStoreLabel = ChangeHope.WebPage.PageRequest.GetQueryInt("IsStoreLabel");
                if (isStoreLabel > -1)
                {
                    this.HyperLink1.NavigateUrl = "mouldtype_list.aspx?w_d_isstoremould=" + isStoreLabel;
                    this.returnLink.NavigateUrl = "mouldtype_list.aspx?w_d_isstoremould=" + isStoreLabel;
                }
            }
        }

        private void Save()
        {
            int isStoreLabel = ChangeHope.WebPage.PageRequest.GetQueryInt("IsStoreLabel");
            BLL.SystemInfo.MouldType bll = new YXShop.BLL.SystemInfo.MouldType();
            Model.SystemInfo.MouldType model = new YXShop.Model.SystemInfo.MouldType();
            try
            {
                model.AddTime = System.DateTime.Now;
                model.Id = ChangeHope.Common.StringHelper.StringToInt(this.txtId.Value);
                model.Name = this.txtName.Text;
                model.Description = this.txtDescription.Text;
                model.IsStoreMould = isStoreLabel;
                if (model.Id > 0)
                {
                    bll.Update(model);
                }
                else
                {
                    this.txtId.Value = bll.Add(model).ToString();
                }
                this.ltlMsg.Text = "保存成功！";
                this.pnlMsg.CssClass = "actionOk";
                this.pnlMsg.Visible = true;
            }
            catch (Exception ex)
            {
                this.ltlMsg.Text = "保存失败:" + ex.ToString();
                this.pnlMsg.CssClass = "actionErr";
                this.pnlMsg.Visible = true;
            }
            finally
            {
                bll = null;
                model = null;
            }
        }
        private void GetModel()
        {
            int id = ChangeHope.WebPage.PageRequest.GetInt("id");
            if (id > 0)
            {
                BLL.SystemInfo.MouldType bll = new YXShop.BLL.SystemInfo.MouldType();
                Model.SystemInfo.MouldType model = bll.GetModel(id);
                if(model!=null)
                {
                    this.txtId.Value = model.Id.ToString();
                    this.txtName.Text = model.Name;
                    this.txtDescription.Text = model.Description;
                }
                model = null;
                bll = null;
            }
        }
        private void InitWebControl()
        {
            ChangeHope.WebPage.WebControl.Validate(this.txtName,"输入模型类别的名称，您将会在以后的创建模型时使用","isnull","必填","该项为必填项");
            ChangeHope.WebPage.WebControl.Validate(this.txtDescription, "输入商品分类的描述作为您以后使用时的一个详细解释", "isnull", "必填", "该项为必填项");
            this.Form.Attributes.Add("onsubmit","return CheckForm()");
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Save();
        }
    }
}
